// logs.js


Page({
  data: {
    codeList: [1, 2, 2],
    code: ''
  },
  throttle(func, delay) {
    let timer = null;
    return function () {
      if (!timer) {
        timer = setTimeout(() => {
          func();
          timer = null;
        }, delay);
      }
    }
  },
  setCode() {
    const code = this.data.codeList
    if (!code.includes(this.data.code)) {
      this.setData({
        codeList: [...code, this.data.code]
      })
    } else {
      wx.showToast({
        title: '重复扫描',
      })
    }
  },
  takeCode(e) {
    this.setData({code: e.detail.result}, () => {
      this.throttle(this.setCode(), 300)
    })
  }
})